package javacafe.serviceimple;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javacafe.dto.studybbs.StudyBBSDTO;
import javacafe.dto.studybbs.StudyBBSReplyDTO;
import javacafe.dto.studybbs.StudyPostDTO;
import javacafe.ibatis.SqlDaoSuport;

public class StudyBBSDAOImpl extends SqlDaoSuport implements StudyBBSDAO {
	
	private static StudyBBSDAO dao;
	
	public static StudyBBSDAO getInstance() {
		if (dao == null) {
			dao = new StudyBBSDAOImpl();
		}
		return dao;
	}

	@Override
	public List<StudyBBSDTO> getStudyBBSList(int study_no) {
		List<StudyBBSDTO> list = null;
		try {
			list = getSqlMapper().queryForList("getStudyBBSList", study_no);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public void createBBS(StudyBBSDTO dto) {
		try {
			getSqlMapper().insert("createBBS", dto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void updateBBS(StudyBBSDTO dto) {
		try {
			getSqlMapper().insert("updateBBS", dto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public List<StudyPostDTO> getStudyPostList(Map<String, Object> map) {
		List<StudyPostDTO> list = null;
		try {
			return (List<StudyPostDTO>)getSqlMapper().queryForList("getStudyPostList", map);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public void insertPost(StudyPostDTO dto) {
		try {
			getSqlMapper().insert("insertStudyPost", dto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public StudyPostDTO getStudyPost(Map<String, Object> map) {
		StudyPostDTO dto = null;
		try {
			dto = (StudyPostDTO)getSqlMapper().queryForObject("getStudyPost", map);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return dto;
	}

	@Override
	public void insertReply(StudyBBSReplyDTO replyDTO) {
		try {
			getSqlMapper().insert("insertPostReply", replyDTO);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public List<StudyBBSReplyDTO> getReplyList(int sp_no) {
		List<StudyBBSReplyDTO> list = null;
		try {
			list = (List<StudyBBSReplyDTO>)getSqlMapper().queryForList("getReplyList", sp_no);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public void updateReply(StudyBBSReplyDTO replyDTO) {
		try {
			getSqlMapper().update("updateStudyReply",replyDTO);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void deleteReply(StudyBBSReplyDTO replyDTO) {
		try {
			getSqlMapper().delete("deleteStudyReply", replyDTO);
		} catch (SQLException e) {
			e.printStackTrace();
		}		
	}

	@Override
	public void deletePost(StudyPostDTO postDto) {
		try {
			getSqlMapper().update("deletePost",postDto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public StudyBBSDTO getStudyBBS(Map<String, Object> map) {
		StudyBBSDTO dto = null;
		try {
			dto = (StudyBBSDTO)getSqlMapper().queryForObject("getStudyBBS", map);
		} catch (Exception e) {
		}
		return dto;
	}

	@Override
	public void updatePost(StudyPostDTO postDto) {
		try {
			getSqlMapper().update("updatePost", postDto);
		} catch (Exception e) {
		}
	}
}
